package simple.flow.modules.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import simple.flow.modules.system.dto.user.LoginUser;
import simple.flow.modules.system.entity.SysUser;
import simple.flow.modules.system.mapper.SysUserMapper;
import simple.flow.modules.system.service.SysUserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * 用户表(SysUser)
 *
 * @author lhd
 * @since 2025-04-02 15:37:52
 */

@Slf4j
@Service
@RequiredArgsConstructor
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    private final SysUserMapper sysUserMapper;

    @Override
    public List<String> getUserRoles(String username) {

        return Collections.emptyList();
    }

    @Override
    public LoginUser getLoginUser(String username) {
        // 用户信息
        LoginUser loginUser = new LoginUser();

        // 查询用户基础信息
        LambdaQueryWrapper<SysUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysUser::getUsername, username);
        SysUser sysUser = sysUserMapper.selectOne(wrapper);
        BeanUtil.copyProperties(sysUser, loginUser);

        // 返回登录用户信息
        return loginUser;
    }
}

